package com.blb.community.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blb.community.pojo.*;
import com.blb.community.service.IZyOwnerRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
public class ZyOwnerRoomController {

    @Autowired
    private IZyOwnerRoomService zyOwnerRoomService;
    // 查询搜索的数据并且分页
    @PostMapping("/property/ownerRoom/index")
    public ResponseResult<Page<ZyOwnerRoom>> findOwnerRoomPage(@RequestBody SelectOwnerRoom selectOwnerRoom) {
        Page<ZyOwnerRoom> ownerRoomPage = zyOwnerRoomService.getOwnerRoomPage(selectOwnerRoom);
        return ResponseResult.ok(ownerRoomPage);
    }
    // 修改
    @PutMapping("/ownerRoom")
    public ResponseResult<String> update(@RequestBody ReqBody reqBody) {
        zyOwnerRoomService.updateOwnerRoom(reqBody);
        return ResponseResult.ok("ok");
    }

    // 添加审核表和审核记录
    @PostMapping("/ownerRoom")
    public ResponseResult<String> add(@RequestBody AddOwnerRoom addOwnerRoom) {
        System.out.println(addOwnerRoom);
        zyOwnerRoomService.addOwnerRoom(addOwnerRoom);
        return ResponseResult.ok("ok");
    }

    // 获取审核记录
    @GetMapping("/ownerRoomRecord")
    public ResponseResult<Page<ZyOwnerRoomRecord>> findZyOwnerRoomRecordPage(@RequestParam(defaultValue = "1") Long page,
                                                                             @RequestParam(defaultValue = "5") Long size) {
        Page<ZyOwnerRoomRecord> zyOwnerRoomRecord = zyOwnerRoomService.getZyOwnerRoomRecord(page, size);
        return ResponseResult.ok(zyOwnerRoomRecord);
    }
    // 获取该用户审核记录
    @GetMapping("/ownerRoomRecord-record")
    public ResponseResult<List<ZyOwnerRoomRecord>> findZyOwnerRoomRecordByOwnerId(@RequestParam Long ownerId) {
        List<ZyOwnerRoomRecord> zyOwnerRoomRecordByOwnerId = zyOwnerRoomService.getZyOwnerRoomRecordByOwnerId(ownerId);
        return ResponseResult.ok(zyOwnerRoomRecordByOwnerId);
    }

    @DeleteMapping("/ownerRoomRecord/{id}")
    public ResponseResult<String> deleteByOwnerId(@PathVariable Long id) {
        zyOwnerRoomService.deleteById(id);
        return ResponseResult.ok("ok");
    }

    @PostMapping("/ownerRoomRecord/{ownerId}")
    public ResponseResult findZyOwnerRoomRecordByBinding(@PathVariable Long ownerId) {
        List<ZyOwnerRoomRecord> zyOwnerRoomRecordByBinding = zyOwnerRoomService.getZyOwnerRoomRecordByBinding(ownerId);
        return ResponseResult.ok(zyOwnerRoomRecordByBinding);
    }
}
